"tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
-[[package]]
-name = "time"
-version = "0.1.34"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
[[package]]
name = "toml"
version = "0.1.28"
use std::env;
use std::fmt;
use std::mem;
-use time;
+use std::time;
use std::iter::repeat;
use std::cell::RefCell;
-thread_local!(static PROFILE_STACK: RefCell<Vec<u64>> = RefCell::new(Vec::new()));
+thread_local!(static PROFILE_STACK: RefCell<Vec<time::Instant>> = RefCell::new(Vec::new()));
thread_local!(static MESSAGES: RefCell<Vec<Message>> = RefCell::new(Vec::new()));
type Message = (usize, u64, String);
pub fn start<T: fmt::Display>(desc: T) -> Profiler {
if enabled_level().is_none() { return Profiler { desc: String::new() } }
- PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::precise_time_ns()));
+ PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::Instant::now()));
Profiler {
desc: desc.to_string(),
};
let start = PROFILE_STACK.with(|stack| stack.borrow_mut().pop().unwrap());
- let end = time::precise_time_ns();
+ let duration = start.elapsed();
+ let duration_ms = duration.as_secs() * 1000 + (duration.subsec_nanos() / 1000000) as u64;
let stack_len = PROFILE_STACK.with(|stack| stack.borrow().len());
if stack_len == 0 {
if l != lvl { continue }
println!("{} {:6}ms - {}",
repeat(" ").take(lvl + 1).collect::<String>(),
- time / 1000000, msg);
+ time, msg);
print(lvl + 1, &msgs[last..i], enabled);
last = i;
}
MESSAGES.with(|msgs_rc| {
let mut msgs = msgs_rc.borrow_mut();
- msgs.push((0, end - start,
+ msgs.push((0, duration_ms,
mem::replace(&mut self.desc, String::new())));
print(0, &msgs, enabled);
});
} else {
MESSAGES.with(|msgs| {
let msg = mem::replace(&mut self.desc, String::new());
- msgs.borrow_mut().push((stack_len, end - start, msg));
+ msgs.borrow_mut().push((stack_len, duration_ms, msg));
});
}
}